package com.itheima.edu.info.manager.pojo;

import com.itheima.edu.info.manager.exception.AgeFormatException;
import com.itheima.edu.info.manager.exception.IdFormatException;
import com.itheima.edu.info.manager.exception.NameFormatException;

public class Student {
    private String id;
    private String name;

    private String age;

    public Student() {
    }

    public Student(String id, String name, String age) {
        if (!id.startsWith("A")) {
            throw new IdFormatException("学号要以A开头");
        }

        if (id.length() != 10) {
            throw new IdFormatException("学号需要10个字符");
        }

        if (name.length() <2 || name.length()>4) {
            throw new NameFormatException("名字需要在2~4长度之间");
        }

        int i = Integer.parseInt(age);
        if (i<18 || i >25) {
            throw new NameFormatException("年龄需要在18~25之间");
        }

        this.id = id;
        this.name = name;
        this.age = age;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        // if (!id.startsWith("A")) {
        //     throw new IdFormatException("学号要以A开头");
        // }
        //
        // if (id.length() != 10) {
        //     throw new IdFormatException("学号需要10个字符");
        // }

        this.id = id;
    }

    // 把学生管理系统加几个校验。分别是 name名字长度2~4个字  年龄 18~25岁

    public String getName() {
        return name;
    }

    public void setName(String name) {
        // if (name.length() <2 || name.length()>4) {
        //     throw new NameFormatException("名字需要在2~4长度之间");
        // }

        this.name = name;
    }

    public String getAge() {
        return age;
    }

    public void setAge(String age) {
        // int i = Integer.parseInt(age);
        // if (i<18 || i >25) {
        //     throw new AgeFormatException("年龄需要在18~25之间");
        // }
        this.age = age;
    }


    @Override
    public String toString() {
        return id+"\t\t"+name+"\t\t"+age+"\t\t";
    }
}
